package post_to_in_pkg.node;

import post_to_in_pkg.lexer.Tag;
import post_to_in_pkg.lexer.Token;
import post_to_in_pkg.parser.Type;

public class TempNode extends OperandNode{
	
	static int temp_var_count=1;
	static final String prefix_of_tempvar="tempvar";
	OperatorNode Operand;
	public TempNode(OperatorNode agr_node) {
		super(
				new Token(prefix_of_tempvar+String.valueOf(temp_var_count++),Tag.TEMP)
				,
				Type.TEMPVAR
			  );
		Operand=agr_node;
	}
	
	static public int getTempVarCount() {
		return temp_var_count;
	}
	
	public boolean isTempNode() {
		return true;
	}
	
	public String toString() {
		String s="\n";
		s=s+"temp "+this.getName()+"="+Operand.toString();
		return s;
	}
	
	public boolean hasChild() {
		if(Operand.hasChild())
			return true;
		else
			return false;			
	}
	
	public void printChild(StringBuffer content) {
		if(hasChild()) {
			StringBuffer str_buf=new StringBuffer();
			Operand.printChild(str_buf);
			str_buf.append(toString()); 
			content=content.insert(0,str_buf);
		}
		else {
			content=content.insert(0,toString());
		}
	}
	
	static public void resetTempvarCount() {
		temp_var_count=1;
	}
}
